package com.fivestyle.controller;


import com.fivestyle.common.result.R;
import com.fivestyle.service.CollectionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 张代钊
 * @since 2021-08-04
 */
@RestController
@RequestMapping("/onlinebook/collection")
public class CollectionController {

    @Autowired
    private CollectionService collectionService;


    @ApiOperation(value = "获取最多收藏的图书",notes = "分页获取最多收藏的图书")
    @GetMapping("maxCollectBook/{current}/{size}")
    public R maxCollectBook(@PathVariable Long current, @PathVariable Long size) {
        return collectionService.maxCollectBook((current-1)*size,size);
    }

//    收藏或者取消收藏
    @ApiOperation(value = "收藏或者取消收藏",notes = "传入用户id，图书id，来取消收藏或者收藏该图书")
    @PutMapping("collectOrNot/{userId}/{bookId}")
    public R collectOrNot(@PathVariable String userId,@PathVariable String bookId){
        return collectionService.collectOrNot(userId,bookId);
    }


}

